﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

using DevExpress.XtraEditors.Controls;
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraEditors;
using MINERP.BLL.InfoConfig;
using MINERP.DAL;
namespace MINERP.InfoConfig.Controller
{
    public  class TechController
    {
        #region //private fields

        private TechBLL _bll = null;
        private GridControl _grid = null;
        private GridView _view = null;
        private ComboBoxEdit _comboBox = null;
        private GroupControl _groupControl = null;
        private CheckEdit _checkEdit = null;

        #endregion


        #region //Public Properties

        internal GroupControl GroupControl
        {
            set
            {
                _groupControl = value;
            }
        }
        internal CheckEdit CheckEdit
        {
            set
            {
                _checkEdit = value;
            }
        }
        internal ComboBoxEdit ComoBox
        {
            set
            {
                _comboBox = value;
            }
        }
        internal GridControl Grid
        {
            set
            {
                _grid = value;
            }
        }

        internal GridView View
        {
            set
            {
                this._view = value;
            }
            get
            {
                return _view;
            }
        }

        #endregion


        #region //Public Methods

        public void GetTechData()
        {
            _bll = new TechBLL();

            List<tb_Tech> list = _bll.GetTechList();
            foreach (var item in list)
            {
                if (item.TechName == "开始" || item.TechName == "完成(结点)" || item.TechName == "拼版" || item.TechName == "打印")
                {
                    item.IsNecessary = true;
                }
            }


            _grid.DataSource = list;
        }

        /// <summary>
        /// 获得所选行的Tech对象
        /// </summary>
        /// <returns></returns>
        public List<tb_Tech> GetCheckedTech()
        {
            List<tb_Tech> list = new List<tb_Tech>();
            for (int i = 0; i < _view.RowCount; i++)
            {
                tb_Tech tech =(tb_Tech)_view.GetRow(i);
                if ((tech.IsNecessary==null)?false:(bool)tech.IsNecessary)
                {
                    list.Add(tech);
                }
            }
            return list;
        }
        /// <summary>
        /// 获得单个节点对象
        /// </summary>
        /// <param name="techId"></param>
        /// <returns></returns>
        public tb_Tech GetTechObj(int id)
        {
            _bll = new TechBLL();
            return _bll.GetTechObj(id);
        }
        /// <summary>
        /// 添加节点
        /// </summary>
        /// <param name="obj"></param>
        public void Add(tb_Tech obj)
        {
            _bll = new TechBLL();
            _bll.Add(obj);
        }
        /// <summary>
        /// 更新节点
        /// </summary>
        public void Update()
        {
            _bll = new TechBLL();
            _bll.Update();
        }
        /// <summary>
        /// 删除节点
        /// </summary>
        /// <param name="obj"></param>
        public void Delete(tb_Tech obj)
        {
            _bll = new TechBLL();
            _bll.Delete(obj);
        }
        #endregion
    }
}
